home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.gsfc.nasa.gov!usenet
- From: MJA <monica@vlsi9.gsfc.nasa.gov>
- Newsgroups: comp.lang.c
- Subject: Loading linked structures from a file--what is standard way?
- Date: 20 Mar 1996 04:34:20 GMT
- Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
- Message-ID: <4io1sd$b6u@post.gsfc.nasa.gov>
- NNTP-Posting-Host: vlsi14.gsfc.nasa.gov
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.3 sun4c)
- X-URL: news:comp.lang.c
-
- Suppose this is my code:
-
- struct HELL {
- char A[];
- char B[];
- char C[];
- int number;
- struct HELL *next;
- } Devil, *ptr;
-
- loadstruct()
- { function loads a structure with data gotten from a configuration file }
-
-
- I have a structure called HELL with elements char A, B, C; and int number;.
- I also have a data file with groups of these elements' data delimited by a :
- and groups separated by a $
-
-
- hot:hotter:hottest:10:$
- spark:flame:fire:20:$
- murder1:murder2:murder3:30:$
-
- Suppose I don't know how many records I have. I will create a dynamically
- linked list. I want to dynamically create, in this case 3 linked structures of
- type HELL.
- I want to malloc space for each new structure and I want *ptr to point to it.
- So, my question is do I pass the *ptr to my loadstruct() function or do I
- create a space for each structure (malloc) and pass the whole structure to my
- function loadstruct()?
-
- If I pass the *ptr, I will of course update it with *ptr = ptr -> *next;
-
- Is this the most efficient way of loading dynamically linked structures from a
- file?
-
- note: I'm not worried about memory, I'm more worried about speed.
-
- Thanks, Monica
-
-